# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
# RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=tahiti -run-pass=amdgpu-prelegalizer-combiner -verify-machineinstrs %s -o - | FileCheck -check-prefix=GFX6 %s
# RUN: llc -mtriple=amdgcn-mesa-mesa3d -mcpu=gfx900 -run-pass=amdgpu-prelegalizer-combiner -verify-machineinstrs %s -o - | FileCheck -check-prefix=GFX9 %s

---
name: narrow_shl_s32_by_2_from_zext_s16
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $vgpr0

    ; GFX6-LABEL: name: narrow_shl_s32_by_2_from_zext_s16
    ; GFX6: liveins: $vgpr0
    ; GFX6-NEXT: {{  $}}
    ; GFX6-NEXT: %argument:_(s32) = COPY $vgpr0
    ; GFX6-NEXT: %narrow:_(s16) = G_TRUNC %argument(s32)
    ; GFX6-NEXT: %masklow14:_(s16) = G_CONSTANT i16 16383
    ; GFX6-NEXT: %masked:_(s16) = G_AND %narrow, %masklow14
    ; GFX6-NEXT: [[C:%[0-9]+]]:_(s16) = G_CONSTANT i16 2
    ; GFX6-NEXT: [[SHL:%[0-9]+]]:_(s16) = G_SHL %masked, [[C]](s16)
    ; GFX6-NEXT: %shl:_(s32) = G_ZEXT [[SHL]](s16)
    ; GFX6-NEXT: $vgpr0 = COPY %shl(s32)
    ; GFX9-LABEL: name: narrow_shl_s32_by_2_from_zext_s16
    ; GFX9: liveins: $vgpr0
    ; GFX9-NEXT: {{  $}}
    ; GFX9-NEXT: %argument:_(s32) = COPY $vgpr0
    ; GFX9-NEXT: %narrow:_(s16) = G_TRUNC %argument(s32)
    ; GFX9-NEXT: %masklow14:_(s16) = G_CONSTANT i16 16383
    ; GFX9-NEXT: %masked:_(s16) = G_AND %narrow, %masklow14
    ; GFX9-NEXT: [[C:%[0-9]+]]:_(s16) = G_CONSTANT i16 2
    ; GFX9-NEXT: [[SHL:%[0-9]+]]:_(s16) = G_SHL %masked, [[C]](s16)
    ; GFX9-NEXT: %shl:_(s32) = G_ZEXT [[SHL]](s16)
    ; GFX9-NEXT: $vgpr0 = COPY %shl(s32)
    %argument:_(s32) = COPY $vgpr0
    %narrow:_(s16) = G_TRUNC %argument
    %masklow14:_(s16) = G_CONSTANT i16 16383
    %masked:_(s16) = G_AND %narrow, %masklow14
    %extend:_(s32) = G_ZEXT %masked
    %shiftamt:_(s32) = G_CONSTANT i32 2
    %shl:_(s32) = G_SHL %extend, %shiftamt
    $vgpr0 = COPY %shl
...

---
name: narrow_shl_s64_by_2_from_zext_s16
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $vgpr0

    ; GFX6-LABEL: name: narrow_shl_s64_by_2_from_zext_s16
    ; GFX6: liveins: $vgpr0
    ; GFX6-NEXT: {{  $}}
    ; GFX6-NEXT: %argument:_(s32) = COPY $vgpr0
    ; GFX6-NEXT: %narrow:_(s16) = G_TRUNC %argument(s32)
    ; GFX6-NEXT: %masklow14:_(s16) = G_CONSTANT i16 16383
    ; GFX6-NEXT: %masked:_(s16) = G_AND %narrow, %masklow14
    ; GFX6-NEXT: [[C:%[0-9]+]]:_(s16) = G_CONSTANT i16 2
    ; GFX6-NEXT: [[SHL:%[0-9]+]]:_(s16) = G_SHL %masked, [[C]](s16)
    ; GFX6-NEXT: %shl:_(s64) = G_ZEXT [[SHL]](s16)
    ; GFX6-NEXT: $vgpr0_vgpr1 = COPY %shl(s64)
    ; GFX9-LABEL: name: narrow_shl_s64_by_2_from_zext_s16
    ; GFX9: liveins: $vgpr0
    ; GFX9-NEXT: {{  $}}
    ; GFX9-NEXT: %argument:_(s32) = COPY $vgpr0
    ; GFX9-NEXT: %narrow:_(s16) = G_TRUNC %argument(s32)
    ; GFX9-NEXT: %masklow14:_(s16) = G_CONSTANT i16 16383
    ; GFX9-NEXT: %masked:_(s16) = G_AND %narrow, %masklow14
    ; GFX9-NEXT: [[C:%[0-9]+]]:_(s16) = G_CONSTANT i16 2
    ; GFX9-NEXT: [[SHL:%[0-9]+]]:_(s16) = G_SHL %masked, [[C]](s16)
    ; GFX9-NEXT: %shl:_(s64) = G_ZEXT [[SHL]](s16)
    ; GFX9-NEXT: $vgpr0_vgpr1 = COPY %shl(s64)
    %argument:_(s32) = COPY $vgpr0
    %narrow:_(s16) = G_TRUNC %argument
    %masklow14:_(s16) = G_CONSTANT i16 16383
    %masked:_(s16) = G_AND %narrow, %masklow14
    %extend:_(s64) = G_ZEXT %masked
    %shiftamt:_(s32) = G_CONSTANT i32 2
    %shl:_(s64) = G_SHL %extend, %shiftamt
    $vgpr0_vgpr1 = COPY %shl
...

---
name: narrow_shl_s16_by_2_from_zext_s8
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $vgpr0

    ; GFX6-LABEL: name: narrow_shl_s16_by_2_from_zext_s8
    ; GFX6: liveins: $vgpr0
    ; GFX6-NEXT: {{  $}}
    ; GFX6-NEXT: %argument:_(s32) = COPY $vgpr0
    ; GFX6-NEXT: %narrow:_(s8) = G_TRUNC %argument(s32)
    ; GFX6-NEXT: %masklow6:_(s8) = G_CONSTANT i8 63
    ; GFX6-NEXT: %masked:_(s8) = G_AND %narrow, %masklow6
    ; GFX6-NEXT: [[C:%[0-9]+]]:_(s8) = G_CONSTANT i8 2
    ; GFX6-NEXT: [[SHL:%[0-9]+]]:_(s8) = G_SHL %masked, [[C]](s8)
    ; GFX6-NEXT: %result:_(s32) = G_ZEXT [[SHL]](s8)
    ; GFX6-NEXT: $vgpr0 = COPY %result(s32)
    ; GFX9-LABEL: name: narrow_shl_s16_by_2_from_zext_s8
    ; GFX9: liveins: $vgpr0
    ; GFX9-NEXT: {{  $}}
    ; GFX9-NEXT: %argument:_(s32) = COPY $vgpr0
    ; GFX9-NEXT: %narrow:_(s8) = G_TRUNC %argument(s32)
    ; GFX9-NEXT: %masklow6:_(s8) = G_CONSTANT i8 63
    ; GFX9-NEXT: %masked:_(s8) = G_AND %narrow, %masklow6
    ; GFX9-NEXT: [[C:%[0-9]+]]:_(s8) = G_CONSTANT i8 2
    ; GFX9-NEXT: [[SHL:%[0-9]+]]:_(s8) = G_SHL %masked, [[C]](s8)
    ; GFX9-NEXT: %result:_(s32) = G_ZEXT [[SHL]](s8)
    ; GFX9-NEXT: $vgpr0 = COPY %result(s32)
    %argument:_(s32) = COPY $vgpr0
    %narrow:_(s8) = G_TRUNC %argument
    %masklow6:_(s8) = G_CONSTANT i8 63
    %masked:_(s8) = G_AND %narrow, %masklow6
    %extend:_(s16) = G_ZEXT %masked
    %shiftamt:_(s16) = G_CONSTANT i16 2
    %shl:_(s16) = G_SHL %extend, %shiftamt
    %result:_(s32) = G_ANYEXT %shl
    $vgpr0 = COPY %result
...

---
name: narrow_shl_v2s32_by_2_from_zext_v2s16
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $vgpr0

    ; GFX6-LABEL: name: narrow_shl_v2s32_by_2_from_zext_v2s16
    ; GFX6: liveins: $vgpr0
    ; GFX6-NEXT: {{  $}}
    ; GFX6-NEXT: %narrow:_(<2 x s16>) = COPY $vgpr0
    ; GFX6-NEXT: %masklow14:_(s16) = G_CONSTANT i16 16383
    ; GFX6-NEXT: %masklow14vec:_(<2 x s16>) = G_BUILD_VECTOR %masklow14(s16), %masklow14(s16)
    ; GFX6-NEXT: %masked:_(<2 x s16>) = G_AND %narrow, %masklow14vec
    ; GFX6-NEXT: %extend:_(<2 x s32>) = G_ZEXT %masked(<2 x s16>)
    ; GFX6-NEXT: %shiftamt:_(s32) = G_CONSTANT i32 2
    ; GFX6-NEXT: %shiftamtvec:_(<2 x s32>) = G_BUILD_VECTOR %shiftamt(s32), %shiftamt(s32)
    ; GFX6-NEXT: %shl:_(<2 x s32>) = G_SHL %extend, %shiftamtvec(<2 x s32>)
    ; GFX6-NEXT: $vgpr0_vgpr1 = COPY %shl(<2 x s32>)
    ; GFX9-LABEL: name: narrow_shl_v2s32_by_2_from_zext_v2s16
    ; GFX9: liveins: $vgpr0
    ; GFX9-NEXT: {{  $}}
    ; GFX9-NEXT: %narrow:_(<2 x s16>) = COPY $vgpr0
    ; GFX9-NEXT: %masklow14:_(s16) = G_CONSTANT i16 16383
    ; GFX9-NEXT: %masklow14vec:_(<2 x s16>) = G_BUILD_VECTOR %masklow14(s16), %masklow14(s16)
    ; GFX9-NEXT: %masked:_(<2 x s16>) = G_AND %narrow, %masklow14vec
    ; GFX9-NEXT: %extend:_(<2 x s32>) = G_ZEXT %masked(<2 x s16>)
    ; GFX9-NEXT: %shiftamt:_(s32) = G_CONSTANT i32 2
    ; GFX9-NEXT: %shiftamtvec:_(<2 x s32>) = G_BUILD_VECTOR %shiftamt(s32), %shiftamt(s32)
    ; GFX9-NEXT: %shl:_(<2 x s32>) = G_SHL %extend, %shiftamtvec(<2 x s32>)
    ; GFX9-NEXT: $vgpr0_vgpr1 = COPY %shl(<2 x s32>)
    %narrow:_(<2 x s16>) = COPY $vgpr0
    %masklow14:_(s16) = G_CONSTANT i16 16383
    %masklow14vec:_(<2 x s16>) = G_BUILD_VECTOR %masklow14, %masklow14
    %masked:_(<2 x s16>) = G_AND %narrow, %masklow14vec
    %extend:_(<2 x s32>) = G_ZEXT %masked
    %shiftamt:_(s32) = G_CONSTANT i32 2
    %shiftamtvec:_(<2 x s32>) = G_BUILD_VECTOR %shiftamt, %shiftamt
    %shl:_(<2 x s32>) = G_SHL %extend, %shiftamtvec
    $vgpr0_vgpr1 = COPY %shl
...

---
name: narrow_shl_v2s64_by_2_from_anyext_v2s32
tracksRegLiveness: true
body:             |
  bb.0:
    liveins: $vgpr0_vgpr1

    ; GFX6-LABEL: name: narrow_shl_v2s64_by_2_from_anyext_v2s32
    ; GFX6: liveins: $vgpr0_vgpr1
    ; GFX6-NEXT: {{  $}}
    ; GFX6-NEXT: %narrow:_(<2 x s32>) = COPY $vgpr0_vgpr1
    ; GFX6-NEXT: %masklow30:_(s32) = G_CONSTANT i32 1073741823
    ; GFX6-NEXT: %masklow30vec:_(<2 x s32>) = G_BUILD_VECTOR %masklow30(s32), %masklow30(s32)
    ; GFX6-NEXT: %masked:_(<2 x s32>) = G_AND %narrow, %masklow30vec
    ; GFX6-NEXT: %extend:_(<2 x s64>) = G_ANYEXT %masked(<2 x s32>)
    ; GFX6-NEXT: %shiftamt:_(s32) = G_CONSTANT i32 2
    ; GFX6-NEXT: %shiftamtvec:_(<2 x s32>) = G_BUILD_VECTOR %shiftamt(s32), %shiftamt(s32)
    ; GFX6-NEXT: %shl:_(<2 x s64>) = G_SHL %extend, %shiftamtvec(<2 x s32>)
    ; GFX6-NEXT: $vgpr0_vgpr1_vgpr2_vgpr3 = COPY %shl(<2 x s64>)
    ; GFX9-LABEL: name: narrow_shl_v2s64_by_2_from_anyext_v2s32
    ; GFX9: liveins: $vgpr0_vgpr1
    ; GFX9-NEXT: {{  $}}
    ; GFX9-NEXT: %narrow:_(<2 x s32>) = COPY $vgpr0_vgpr1
    ; GFX9-NEXT: %masklow30:_(s32) = G_CONSTANT i32 1073741823
    ; GFX9-NEXT: %masklow30vec:_(<2 x s32>) = G_BUILD_VECTOR %masklow30(s32), %masklow30(s32)
    ; GFX9-NEXT: %masked:_(<2 x s32>) = G_AND %narrow, %masklow30vec
    ; GFX9-NEXT: %extend:_(<2 x s64>) = G_ANYEXT %masked(<2 x s32>)
    ; GFX9-NEXT: %shiftamt:_(s32) = G_CONSTANT i32 2
    ; GFX9-NEXT: %shiftamtvec:_(<2 x s32>) = G_BUILD_VECTOR %shiftamt(s32), %shiftamt(s32)
    ; GFX9-NEXT: %shl:_(<2 x s64>) = G_SHL %extend, %shiftamtvec(<2 x s32>)
    ; GFX9-NEXT: $vgpr0_vgpr1_vgpr2_vgpr3 = COPY %shl(<2 x s64>)
    %narrow:_(<2 x s32>) = COPY $vgpr0_vgpr1
    %masklow30:_(s32) = G_CONSTANT i32 1073741823
    %masklow30vec:_(<2 x s32>) = G_BUILD_VECTOR %masklow30, %masklow30
    %masked:_(<2 x s32>) = G_AND %narrow, %masklow30vec
    %extend:_(<2 x s64>) = G_ANYEXT %masked
    %shiftamt:_(s32) = G_CONSTANT i32 2
    %shiftamtvec:_(<2 x s32>) = G_BUILD_VECTOR %shiftamt, %shiftamt
    %shl:_(<2 x s64>) = G_SHL %extend, %shiftamtvec
    $vgpr0_vgpr1_vgpr2_vgpr3 = COPY %shl
...
